Skip to content

test: expand main-process unit coverage#965

Closed
notluquis wants to merge 7 commits into
masterfrom
phase2/test-expansion
Closed

test: expand main-process unit coverage#965
notluquis wants to merge 7 commits into
masterfrom
phase2/test-expansion

Conversation

@notluquis

Copy link
Copy Markdown
Collaborator

Second of the Phase 2 PRs from the plan in #951, building on the test infra merged in #961.

Adds unit coverage for the main process: tokens, event types, utils, settings, workspace settings, appdata, sessionconfig, cli + cli handlers, and the EventManager. Commits are split by area so each can be reviewed on its own. No application code in src/main/ or src/browser/ changes here, only tests plus one mock fix.

A couple of things worth flagging from writing these:

  • The import paths use 2 dots from test/unit (../../src/main/...). While converting from an earlier 3-dot version I noticed the 3-dot paths were silently not applying the vi.mock factories, so some tests were exercising the real modules instead of the mocks. Fixing the paths surfaced a stale mock field in the cli test (discoveredPythonPaths vs the real discoveredPythonEnvs), now corrected.
  • eventmanager.ts calls ipcMain.removeListener in unregisterAllEventHandlers, but the shared electron mock had dropped that method, so the dispose tests failed until it was restored.
  • The getRelativePathToUserHome test was a typeof === 'function' tautology; rewrote it to assert the actual ~-prefixed output, and confirmed with a mutation (returning the raw path fails the test).

Local verification: yarn test:unit 305/305, npx tsc --noEmit exit 0, prettier and eslint clean on test/.

Husky/lint-staged and the cross-platform CI work follow in a later PR.

Note: AI-assisted (Claude Code). Manually verified: the 2-dot path / mock behavior above, the EventManager removeListener failure and fix, and the getRelativePathToUserHome mutation check, all run locally on macOS.

notluquis added 7 commits May 22, 2026 04:19
EnvironmentTypeName mapping plus IEventTypeMain/Renderer registry shape.

Note: AI-assisted (Claude Code). Manually verified: 2-dot import paths, vitest green, no tautological asserts (enum-completeness loop pairs toBeDefined with a typeof string check).
Path/home resolution, port checks, env path builders, wait helpers.

Note: AI-assisted (Claude Code). Manually verified: rewrote getRelativePathToUserHome from a typeof-function tautology to a behavioral assertion, mutation check (return absolutePath instead of the ~ form) fails the test and restoring passes.
Default values, setValue overrides, persisted application data shape.

Note: AI-assisted (Claude Code). Manually verified: 2-dot paths, removed unused imports, made the workspace override test assert the pre-override default differs from the new value, vitest green.
Remote vs local sessions, working dir resolution, python path inclusion.

Note: AI-assisted (Claude Code). Manually verified: 2-dot paths, the toBeDefined matchers are each paired with concrete assertions on isRemote/remoteURL/pythonPath, vitest green.
parseCLIArgs subcommands and the env list/handler paths.

Note: AI-assisted (Claude Code). Manually verified: switching to 2-dot paths made the appdata mock actually apply, which exposed a stale mock field (discoveredPythonPaths vs discoveredPythonEnvs); fixed the mock to match the real shape, vitest green.
Sync and async handler registration, dispose unregistering all handlers.

Restore ipcMain.removeListener on the electron mock; eventmanager.ts uses
it in unregisterAllEventHandlers and the mock had dropped it.

Note: AI-assisted (Claude Code). Manually verified: dispose tests failed with "removeListener is not a function" until the mock was restored, then 305/305 green.
Copilot AI review requested due to automatic review settings May 22, 2026 08:28
@notluquis notluquis closed this May 22, 2026
@notluquis notluquis removed the request for review from Copilot May 22, 2026 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant